package bean.control;

import java.io.Serializable;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.mail.MessagingException;
import javax.mail.internet.AddressException;
import javax.servlet.http.HttpSession;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import util.Crypto;
import util.Email;
import bean.entity.FeedBean;
import bean.entity.PersonBean;
import bean.entity.UserBean;
import bean.util.Authorization;
import bean.view.View;
import eao.EaoPerson;
import eao.EaoProduct;
import eao.EaoUser;
import eao.EaoUserPicture;
import eao.EaoUserSocialNetwork;
import entity.Person;
import entity.Product;
import entity.SocialNetwork;
import entity.User;
import entity.UserPicture;
import entity.UserSocialNetwork;
import entity.UserType;

@ManagedBean(name="feedc")
@ViewScoped
public class FeedControl implements Serializable {
	private static final long serialVersionUID = 5303040925167920879L;
	
	@EJB EaoProduct eaoProduct;
	
	@ManagedProperty("#{feedBean}")
	FeedBean feedb;
	
	public void lastestProducts(){
		
		System.out.println("FIRST: " + feedb.getFirst());
		System.out.println("LAST: " + feedb.getLast());
		
		for (Product p : eaoProduct.listLastest(feedb.getFirst(), feedb.getLast())){
			feedb.getProducts().add(p);
		}
	}
	
	public void previous(){
		feedb.getProducts().clear();
		
		feedb.setLast(feedb.getFirst() - 1);
		feedb.setFirst(feedb.getLast() - 10);
		
		this.lastestProducts();
	}

	public void next(){
		feedb.getProducts().clear();
		
		feedb.setFirst(feedb.getLast() + 1);
		feedb.setLast(feedb.getLast() + 10);
		
		this.lastestProducts();
	}
	
	/* Getter's and Setter's  */
	
	public FeedBean getFeedb() {
		return feedb;
	}

	public void setFeedb(FeedBean feedb) {
		this.feedb = feedb;
	}
	
	
	

}
